package com.beimin.evedata.hibernate;

import com.beimin.evedata.model.dgm.DgmTypeAttribute;
import com.beimin.evedata.repository.DgmRepository;
import java.util.Collection;
import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Restrictions;

/**
 *
 * @author Candle
 */
public class HibDgmRepository implements DgmRepository {
	private final SessionFactory sf;

  public HibDgmRepository(SessionFactory sf) {
    this.sf = sf;
  }

  @Override
  public Collection<DgmTypeAttribute> getAttributesForType(int typeId) {
		Session session = sf.getCurrentSession();
		Criteria criteria = session.createCriteria(DgmTypeAttribute.class);
		criteria.add(Restrictions.eq("id.type.typeID", typeId));
		return criteria.list();
  }

  @Override
  public DgmTypeAttribute getAttributeForType(int typeId, int attributeId) {
		Session session = sf.getCurrentSession();
		Criteria criteria = session
            .createCriteria(DgmTypeAttribute.class)
            .add(Restrictions.eq("id.type.typeID", typeId))
            .add(Restrictions.eq("id.attribute.attributeID", attributeId))
            ;
		return (DgmTypeAttribute)criteria.uniqueResult();
  }
}
